package cn.wolfcode.trip.app.interceptor;


import cn.wolfcode.trip.app.util.UserContext;
import cn.wolfcode.trip.base.domain.User;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LoginInterceptor extends HandlerInterceptorAdapter{
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        //判断是否有登录状态
        User currentUser = UserContext.getCurrentUser();
        if(currentUser==null){
            //重定向到登录页面
            response.sendRedirect("/login.html");
            return false;
        }
        return  true;
    }
}
